package com.andnnl.jm;

import cn.hutool.json.JSONUtil;

/**
 * Created by chenss on 2022/9/26.
 */
public class GenLoginCodeUtil {

    public static final String KEY = "Q4YTc4ZTI0Y2Y3Z";

    public static void main(String[] args) {
        String code=genCode("asdf222",System.currentTimeMillis());
        System.out.println(code);
        UserInfo uf = decode(code);
        System.out.println(uf);
        System.out.println(uf.getUserName());
    }

    public static String genCode(String userName, long currentTimeMillis) {
        UserInfo userInfo = new UserInfo(userName,currentTimeMillis);
        String json=JSONUtil.toJsonStr(userInfo);
        return DesUrlParamUtil.encrypt(KEY,json);
    }

    public static UserInfo decode(String str) {
        String json= DesUrlParamUtil.decrypt(KEY,str);
        UserInfo bean=JSONUtil.toBean(json,UserInfo.class);
        return bean;
    }
}
